/*7-4 是否同一棵二叉搜索树 (25 分)*/
#include<iostream>
using namespace std;

typedef struct bnode{
    int data;
    bnode *left,*right;
    bool flag;
}bnode,*btree;

btree New_node(int x){
    btree bt = (btree)malloc(sizeof(btree));
    bt->data = x;
    bt->left = bt->right = NULL;
    bt->flag = false;
    return bt;
}

btree insert_node(btree bt,int v){
    if(!bt){
        bt = New_node(v);
    }else if(v<bt->data){
        bt->left = insert_node(bt->left,v);
    }else{
        bt->right = insert_node(bt->right,v);
    }
}

btree make_tree(int N){
    btree bt;
    int v;
    scanf("%d",&v);
    bt = New_node(v);
    for(int i=0;i<N-1;i++){
        scanf("%d",&v);
        bt = insert_node(bt,v);
    }
    return bt;
}

void reset_tree(btree bt){
    if(bt){
        bt->flag = false;
        reset_tree(bt->left);
        reset_tree(bt->right);
    }
}

void free_tree(btree bt){
    if(bt){
        free_tree(bt->left);
        free_tree(bt->right);
        free(bt);
    }
}

int check_tree(btree bt,int v){
    if(bt->flag){
        if(v<bt->data){
            return check_tree(bt->left,v);
        }else if(v>bt->data){
            return check_tree(bt->right,v);
        }else{
            return false;
        }
    }else{
        if(v==bt->data){
            bt->flag = true;
            return true;
        }else{
            return false;
        }
    }
}

int judge_tree(btree bt,int N){
    int v,flag=0;
    scanf("%d",&v);
    if(v!=bt->data){
        flag = true;//有问题
    }else{
        bt->flag = true;
    }
    for(int i=0;i<N;i++){
        scanf("%d",&v);
        if((!flag)&&(!check_tree(bt,v))){
            flag = true;
        }
    }
    if(flag){
        return false;
    }else{
        return true;
    }
}

int main(){
    int n,l;
    btree bt;
    scanf("%d",&n);
    while(n){
        scanf("%d",&l);
        bt = make_tree(n);
        for(int i=0;i<l;i++){
            if(judge_tree(bt,n)){
                printf("Yes\n");
            }else{
                printf("No\n");
            }
            reset_tree(bt);
        }
        free_tree(bt);
        scanf("%d",&n);
    }
    return 0;
}